﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Finance_search : System.Web.UI.Page
{

    //protected void Page_Load(object sender, EventArgs e)
    //{

    //}


    //// 将数据绑定到gvBillList的相应项
    //protected void gvBillList_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.DataRow)
    //    {
    //        Bill bill = e.Row.DataItem as Bill;

    //        //绑定是否结算了
    //        LinkButton lbtnFinanceAudit = (LinkButton)e.Row.FindControl("lbtnFinanceAudit");
    //        HyperLink hlEdit = (HyperLink)e.Row.FindControl("hlEdit");
    //        Image imgAuditSuccess = (Image)e.Row.FindControl("imgAuditSuccess");
    //        if (bill.FinanceAudit == Audit.Success)
    //        {
    //            imgAuditSuccess.Visible = true;
    //            hlEdit.Enabled = false;
    //            //lbtnFinanceAudit.Text = "取消结算";
    //        }

    //        // 绑定客户名
    //        Label lblCustomerName = (Label)e.Row.FindControl("lblCustomerName");
    //        lblCustomerName.Text = bill.Customer.Name;


    //        //绑定应收款
    //        Label lblFinalRealIncome = (Label)e.Row.FindControl("lblFinalRealIncome");
    //        decimal totalFinalRealIncome = 0;
    //        if (bill.Orders != null)
    //        {
    //            foreach (Order od in bill.Orders)
    //            {
    //                if (od.CustomerOrders != null)
    //                {
    //                    foreach (CustomerOrder co in od.CustomerOrders)
    //                    {
    //                        totalFinalRealIncome += co.RealPayout;
    //                    }
    //                }
    //            }
    //        }
    //        if (totalFinalRealIncome == 0)
    //        {
    //            lblFinalRealIncome.Text = "<font color='#FF0000'>无记录</font>";
    //        }
    //        else
    //        {
    //            lblFinalRealIncome.Text = totalFinalRealIncome.ToString("c");
    //        }

    //        // 绑定已收款
    //        Label lblAlreadyIncome = (Label)e.Row.FindControl("lblAlreadyIncome");
    //        decimal totalAlreadyIncome = 0;
    //        if (bill.Orders != null)
    //        {
    //            foreach (Order od in bill.Orders)
    //            {
    //                if (od.IncomeRecords != null)
    //                {
    //                    foreach (IncomeRecord incomeRecord in od.IncomeRecords)
    //                    {
    //                        totalAlreadyIncome += incomeRecord.Income;
    //                    }
    //                }
    //            }
    //        }
    //        if (totalAlreadyIncome == 0)
    //        {
    //            lblAlreadyIncome.Text = "<font color='#FF0000'>未收</font>";
    //        }
    //        else
    //        {
    //            if (totalAlreadyIncome - totalFinalRealIncome >= 0)
    //            {
    //                lblAlreadyIncome.Text = "<font color='#FF0000'><B>√ </B></font>" + totalAlreadyIncome.ToString("c");
    //            }
    //            else { lblAlreadyIncome.Text = totalAlreadyIncome.ToString("c"); }
    //        }

    //        //绑定应付款
    //        Label lblRealPayout = (Label)e.Row.FindControl("lblRealPayout");
    //        decimal totalRealPayout = 0;
    //        if (bill.Orders != null)
    //        {
    //            foreach (Order odr in bill.Orders)
    //            {
    //                if (odr.MediaOrders != null)
    //                {
    //                    foreach (MediaOrder mor in odr.MediaOrders)
    //                    {
    //                        totalRealPayout += mor.RealPayout;
    //                    }
    //                }
    //            }
    //        }
    //        if (totalRealPayout == 0)
    //        {
    //            lblRealPayout.Text = "<font color='#FF0000'>无记录</font>";
    //        }
    //        else
    //        {
    //            lblRealPayout.Text = totalRealPayout.ToString("c");
    //        }

    //        //绑定已付款
    //        Label lblAlreadyPayout = (Label)e.Row.FindControl("lblAlreadyPayout");
    //        decimal totalAlreadyPayout = 0;
    //        if (bill.Orders != null)
    //        {
    //            foreach (Order od in bill.Orders)
    //            {
    //                if (od.PayoutRecords != null)
    //                {
    //                    foreach (PayoutRecord por in od.PayoutRecords)
    //                    {
    //                        totalAlreadyPayout += por.Payout;
    //                    }
    //                }
    //            }
    //        }
    //        if (totalAlreadyPayout == 0)
    //        {
    //            lblAlreadyPayout.Text = "<font color='#FF0000'>未付</font>";
    //        }
    //        else
    //        {
    //            lblAlreadyPayout.Text = totalAlreadyPayout.ToString("c");
    //        }

    //        //鼠标悬停在已收上时显示已收款与应收款的差额
    //        if (totalFinalRealIncome != 0)
    //        {
    //            //lblFinalRealIncome.ToolTip = (totalAlreadyIncome - totalFinalRealIncome).ToString("c"); ;
    //            lblAlreadyIncome.ToolTip = "应收客户：" + totalFinalRealIncome.ToString("c") + "\n已收客户：" + totalAlreadyIncome.ToString("c") + "\n　　差额：" + (totalAlreadyIncome - totalFinalRealIncome).ToString("c");
    //        }
    //        if (totalFinalRealIncome != 0 && totalRealPayout != 0)
    //        {
    //            lblRealPayout.ToolTip = "应收客户：" + totalFinalRealIncome.ToString("c") + "\n应付媒体：" + totalRealPayout.ToString("c") + "\n　　差额：" + (totalFinalRealIncome - totalRealPayout).ToString("c");
    //        }
    //        if (totalRealPayout != 0 && totalAlreadyPayout != 0)
    //        {
    //            lblAlreadyPayout.ToolTip = "应付媒体：" + totalRealPayout.ToString("c") + "\n已付媒体：" + totalAlreadyPayout.ToString("c") + "\n　　差额：" + (totalAlreadyPayout - totalRealPayout).ToString("c");
    //        }
    //    }
    //}



    //protected void gvBillList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    this.gvBillList.PageIndex = e.NewPageIndex;
    //    if (dlSearchType.SelectedIndex == 0)
    //    {
    //        lblMessage.Visible = false;
    //        string strSelect = null;
    //        if (txtId.Text.Length > 0)
    //        { strSelect = txtId.Text.ToString(); }
    //        pnResult.Visible = true;
    //        //gvBillList.DataSource = DataService.SearchBillForFinance(strSelect, null, null);
    //        gvBillList.DataBind();
    //        if (gvBillList.Rows.Count <= 0)
    //        { lblMessage.Visible = true; }
    //    }
    //    else if (dlSearchType.SelectedIndex == 1)
    //    {
    //        string strFirstDate = null;
    //        lblMessage.Visible = false;
    //        if (txtFirstDate.Text.Length != 0)
    //        { strFirstDate = txtFirstDate.Text.ToString(); }
    //        string strLastDate = null;
    //        if (txtLastDate.Text.Length != 0)
    //        { strLastDate = txtLastDate.Text.ToString(); }
    //        pnResult.Visible = true;
    //        //gvBillList.DataSource = DataService.SearchBillForFinance(null, strFirstDate, strLastDate);
    //        gvBillList.DataBind();
    //        if (gvBillList.Rows.Count <= 0)
    //        { lblMessage.Visible = true; }
    //    }
        
    //}
   
    
    //protected void btnSearch_Click(object sender, EventArgs e)
    //{
    //    if (dlSearchType.SelectedIndex == 0)
    //    {
    //        lblMessage.Visible = false;
    //        string strSelect = null;
    //        if (txtId.Text.Length > 0)
    //        { strSelect = txtId.Text.ToString(); }
    //        pnResult.Visible = true;
    //        //gvBillList.DataSource = DataService.SearchBillForFinance(strSelect, null, null);
    //        gvBillList.DataBind();
    //        if (gvBillList.Rows.Count <= 0)
    //        { lblMessage.Visible = true; }
    //    }
    //    else if (dlSearchType.SelectedIndex == 1)
    //    {
    //        string strFirstDate = null;
    //        lblMessage.Visible = false;
    //        if (txtFirstDate.Text.Length != 0)
    //        { strFirstDate = txtFirstDate.Text.ToString(); }
    //        string strLastDate = null;
    //        if (txtLastDate.Text.Length != 0)
    //        { strLastDate = txtLastDate.Text.ToString(); }
    //        pnResult.Visible = true;
    //        //gvBillList.DataSource = DataService.SearchBillForFinance(null, strFirstDate, strLastDate);
    //        gvBillList.DataBind();
    //        if (gvBillList.Rows.Count <= 0)
    //        { lblMessage.Visible = true; }
    //    }

    //}
}
